home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / uuinout / uuprepare.rexx < prev   
OS/2 REXX Batch file  |  1995-03-09  |  4KB  |  107 lines

  1. /*******************************************************************\
  2.  
  3. $VER: 1.03 (8.12.93) by Nicolas Dade. This is public domain
  4.  
  5. This arexx program prepares a binary file for posting by
  6. uuencoding it, breaking it up into multiple parts, and giving
  7. each part a nice header and tail.
  8.  
  9. Feel free to modify the headline and tailline to your taste.
  10. Please note that the total number of parts is not available in
  11. this program. To know it requires that uuIn have finished encoding,
  12. and this program is pipe: driven, so uuIn is not finished when the
  13. headline and tailline are created. This means that your head and
  14. tail lines cannot say something like "part X of Y". If you really
  15. want this, you'll have to change the program so that uuIn is run to
  16. completion, leaving its output in "t:", then the number of output
  17. files is counted, and finally the files in "t:" have the header,
  18. headline and tailline added to them as they are copied to the final
  19. destination.
  20.  
  21. This program requires the program uuIn to be somewhere in your
  22. path, since it uses uuIn to uuencode and split the files.
  23.  
  24.  
  25. use: (from a shell)
  26.  
  27.   rx uuPrepare binaryfile headerfile
  28.  
  29. produces outputs called binaryfile.uu1, binaryfile.uu2, ... . Each file
  30. consists of a copy of headerfile, the headline, about NOMINAL_LINES_PER-
  31. _FILE or fewer lines of uuencoded data, and the tailline.
  32.  
  33. A headerfile is not required.
  34.  
  35. \*******************************************************************/
  36.  
  37. /* each file has slightly more than NOMINAL_LINES_PER_FILE lines */
  38. NOMINAL_LINES_PER_FILE = 700
  39. /* I do my IO in IO_SIZE chunks. IO_SIZE should be at least 25 bytes */
  40. IO_SIZE=16000
  41.  
  42. parse arg binaryname headertextname .
  43.  
  44. /* create a few names */
  45. dataname=right(binaryname,length(binaryname)-max(lastpos(':',binaryname),lastpos('/',binaryname)))
  46. pipebasename = 'pipe:uuPrepare'||pragma('ID')||dataname'.uu'
  47.  
  48. /* start the file encoding process */
  49. address command 'run uuIn INFILE="'binaryname'" OUTFILE="'pipebasename'" MAXLINES='NOMINAL_LINES_PER_FILE' NORENAME'
  50. if rc>0 then do
  51.   say 'uuPrepare ABORTING: run uuIn failed'
  52.   exit 10
  53. end
  54.  
  55. /* pull part-files out of the pipes, adding headers and tailers */
  56. do partnum=1
  57.   inpartname = pipebasename||partnum
  58.   outpartname = binaryname||'.uu'||partnum
  59.   say 'uuPreparing part 'partnum' of "'binaryname'" into "'outpartname'" (from "'inpartname'")'
  60.   if ~open('inpart',inpartname,'R') then do
  61.     say 'uuPrepare ABORTING after 'partnum-1' parts: couldn''t open "'inpartname'"'
  62.     exit 10
  63.   end
  64.   if ~open('outpart',outpartname,'W') then do
  65.     say 'uuPrepare aborting after 'partnum-1' parts: couldn''t open "'outpartname'"'
  66.     exit 10
  67.   end
  68.   /* copy header text file to the top of this part's file */
  69.   if headertextname~='' then do
  70.     if ~open('header',headertextname,'R') then do
  71.       say 'uuPrepare WARNING: couldn''t open headertextfile "'headertextname'"'
  72.       say 'there will be no header text in "'outpartname'"'
  73.     end
  74.     else do
  75.       do while ~eof('header')
  76.     writech('outpart',readch('header',IO_SIZE)) /* copy the header file */
  77.       end
  78.       close('header')
  79.     end
  80.   end
  81.   headline='----BEGIN----begin----'dataname'----part 'partnum'----'
  82.   if length(headline)<75 then headline=left(headline,65,'-') /* add -'s as needed */
  83.   writeln('outpart',headline)
  84.   data=''
  85.   last25data=''
  86.   do while ~eof('inpart')
  87.     /* move some data */
  88.     data=readch('inpart',IO_SIZE)
  89.     writech('outpart',data)
  90.     /* keep the last 25 bytes of the file around so that we can check for the 'end' line */
  91.     if length(data)>=25 then last25data=right(data,25)
  92.     else last25data=right(last25data||data,25,' ')
  93.   end
  94.   tailline='-----END------end-----'dataname'----part 'partnum'----'
  95.   if length(tailline)<75 then tailline=left(tailline,65,'-')
  96.   writeln('outpart',tailline)
  97.   writeln('outpart','')
  98.   close('inpart')
  99.   close('outpart')
  100.   /* check to see if this was the last part by looking for an 'end' line in the data */
  101.   if pos('end',last25data)~=0 then leave
  102. end
  103.  
  104. say 'uuPreparation of "'binaryname'" is finished'
  105. exit 0
  106.  
  107.